package com.gjt.thread.Thread;

import com.gjt.thread.Main;
import org.springframework.cache.annotation.Cacheable;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.Callable;

/**
 * Created with Intel IDEA.
 * 这个线程读取一个文件的前n个字节 另一个线程读取全部
 *
 * @Auther: gjt
 * @Date: 2024/3/20 22:59
 */
public class ReadPartFileThread implements Callable<char[]> {
    private Main thread;
    private InputStream in;

    public ReadPartFileThread(Main thread, InputStream in) {
        this.thread = thread;
        this.in = in;
    }

    @Override
    public synchronized char[] call() throws Exception {
        char[] list=new char[100];
        try{
            InputStreamReader reader = new InputStreamReader(in);
            reader.read(list,0,100);
            thread.notify();
        }catch (IOException e){
            e.printStackTrace();
        }
        return list;
    }
}
